package org.ls.petclinic.web;

import com.google.gson.Gson;
import org.ls.petclinic.dao.VetDao;
import org.ls.petclinic.dao.impl.VetDaoImpl;
import org.ls.petclinic.pojo.Vet;
import org.ls.petclinic.untils.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description
 * @Author 浪矢先生
 * @Create 2022-06-09 23:30
 */
@WebServlet(urlPatterns = "/getVets")
public class GetVetsServlet extends BaseServlet{
    private VetDao vetDao=new VetDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Vet> vetList = vetDao.getVetList();
        JdbcUtils.commitAndClose();
        Gson gson = new Gson();
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");
        resp.getWriter().write(String.valueOf(gson.toJson(vetList)));
    }
}
